#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Instruments/Swap.h>
#pragma unmanaged 
#include <ql\instruments\assetswap.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IAssetSwap
	public ref class CAssetSwap : 
            public CSwap,
            public Cephei::QL::Instruments::IAssetSwap
	{
	protected: 
		boost::shared_ptr<QuantLib::AssetSwap>* _ppAssetSwap;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AssetSwap>* _phAssetSwap;
#endif
		Object^ _AssetSwapOwner;     // reference to object that manages the storage for this object
	internal:
		CAssetSwap (Boolean payFixedRate, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Cephei::QL::Indexes::IIborIndex^ index, Double spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>^ floatSchedule, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<Boolean>^ parAssetSwap, Cephei::QL::IPricingEngine^ QL_Pricer);
        CAssetSwap (boost::shared_ptr<QuantLib::AssetSwap>& childNative, Object^ owner);
        CAssetSwap (QuantLib::AssetSwap& childNative, Object^ owner);
        CAssetSwap (CAssetSwap^ copy);
        CAssetSwap (System::Type^ t);
#ifdef STRUCT
        CAssetSwap (QuantLib::AssetSwap childNative);
#endif       
#ifdef HANDLE
		CAssetSwap (QuantLib::Handle<QuantLib::AssetSwap>& childNative, Object^ owner);
		CAssetSwap (QuantLib::Handle<QuantLib::AssetSwap> childNative);
#endif
		virtual ~CAssetSwap ();
		!CAssetSwap ();

	internal:
		QuantLib::AssetSwap& GetReference ();
		boost::shared_ptr<QuantLib::AssetSwap>& GetShared ();
		QuantLib::AssetSwap* GetPointer ();
        void SetAssetSwap (boost::shared_ptr<QuantLib::AssetSwap> native)
        {
            if (_ppAssetSwap != NULL)
                delete _ppAssetSwap;
            _ppAssetSwap = new boost::shared_ptr<QuantLib::AssetSwap> (native);
            SetSwap (boost::dynamic_pointer_cast<QuantLib::Swap> (*_ppAssetSwap));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::AssetSwap>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::IVector<Cephei::QL::ICashFlow^>^ BondLeg 
        {
		    virtual Cephei::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Double FairSpread 
        {
		    virtual Double get () ;
        }
        property Cephei::IVector<Cephei::QL::ICashFlow^>^ FloatingLeg 
        {
		    virtual Cephei::IVector<Cephei::QL::ICashFlow^>^ get () ;
        }
        property Cephei::QL::Instruments::IBond^ Bond 
        {
		    virtual Cephei::QL::Instruments::IBond^ get () ;
        }
        property Double FloatingLegBPS 
        {
		    virtual Double get () ;
        }
        property Boolean PayFixedRate 
        {
		    virtual Boolean get () ;
        }
        property Double Spread 
        {
		    virtual Double get () ;
        }
        property Double FairCleanPrice 
        {
		    virtual Double get () ;
        }
        property Boolean ParSwap 
        {
		    virtual Boolean get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CAssetSwap_Factory : public System::MarshalByRefObject,  public IAssetSwap_Factory
	{
	public:
        virtual IAssetSwap^ Create (Boolean payFixedRate, Cephei::QL::Instruments::IBond^ bond, Double bondCleanPrice, Cephei::QL::Indexes::IIborIndex^ index, Double spread, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::ISchedule^>^ floatSchedule, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IDayCounter^>^ floatingDayCount, Microsoft::FSharp::Core::FSharpOption<Boolean>^ parAssetSwap, Cephei::QL::IPricingEngine^ QL_Pricer);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
